package com.liruo.demo.serialize.jackson;

import cn.hutool.core.io.FileUtil;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;

public class ResultLogger implements Closeable {

  private final String filepath;
  private final StringBuilder sb = new StringBuilder();

  public ResultLogger(String qualifier) {
    this.filepath = "src/test/java/" + qualifier + ".txt";
  }

  public void outputLn(String str) {
    sb.append(str + "\n");
  }

  public void output(String str) {
    sb.append(str);
  }

  @Override
  public void close() throws IOException {
    String str = sb.toString();
    if (str.isEmpty()) {
      return;
    }
    FileUtil.writeBytes(str.getBytes(), new File(filepath));

  }
}
